package com.zzy.ecommerce.dao;

import com.zzy.ecommerce.domain.Order;
import com.zzy.ecommerce.domain.TOrder;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

@Mapper
public interface TOrderMapper {

    @Select("select o.id,o.orderCount,o.orderPrice,g.goodsId,g.goodsName,g.goodsPrice,u.username from t_order o join t_user u on o.userId=u.id join t_goods g on o.goodsId=g.goodsId")
    List<Order> selectAllOrder();

    @Select("select * from t_order where id=#{id}")
    TOrder selectOneOrder(Integer id);

    @Delete("delete from t_order where id=#{id}")
    Integer deleteOneOrder(Integer id);

    @Delete("delete from t_order")
    Integer deleteAllOrders();

    @Insert("insert into t_order(userId,goodsId,orderCount,orderPrice) values(#{userid},#{goodsid},#{ordercount},#{orderprice})")
    Integer insertOneOrder(TOrder tOrder);

    @Select("select * from t_order where userId=#{id}")
    List<TOrder> selectAllUserOrder(Integer id);

    @Select("select sum(orderPrice) from t_order where userId=#{id}")
    Double selectOneUserAllOrderPrice(Integer id);

    @Select("select * from t_order where id=#{id}")
    TOrder selectOneOrderById(Integer id);
}